<?php

namespace Liuhelong\LaravelAdmin\Wechat\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Encore\Admin\Traits\DefaultDatetimeFormat;

class WechatOffiaccountCsMessage extends Model
{
    use HasFactory,DefaultDatetimeFormat;
    
	protected $appends = ['text','reply_media','news','miniprogrampage_data'];
	protected $medias = ['image','voice','video','mpnewsarticle'];
	
	public function setTextAttribute($value)
    {
        $this->attributes['reply_content'] = $value;
    }
	public function setReplyMediaAttribute($value)
    {
        $this->attributes['reply_content'] = $value;
    }
	public function setNewsAttribute($value)
    {
        $this->attributes['reply_content'] = $value;
    }
	public function setMiniprogrampageDataAttribute($value)
    {
        $this->attributes['reply_content'] = json_encode($value);
    }
	
	public function getTextAttribute()
    {
        return $this->reply_type=='text'?$this->reply_content:'';
    }
	public function getReplyMediaAttribute()
    {
        return in_array($this->reply_type,$this->medias)?$this->reply_content:'';
    }
	public function getNewsAttribute()
    {
        return $this->reply_type=='news'?$this->reply_content:'';
    }
	public function getMiniprogrampageDataAttribute()
    {
        return $this->reply_type=='miniprogrampage'?json_decode($this->reply_content,true):[];
    }
	
}
